'use strict';
const fs=require('fs');
const http=require('http');
const path=require('path');
const url=require('url');


// var options={
//     key:fs.readFileSync('***'),
//     cert:fs.readFileSync('***')
// }

http.createServer((req,resp)=>{
    let filepath=path.join('./',url.parse(decodeURIComponent(req.url)).pathname);
    console.log(filepath)
    fs.stat(filepath,(err,stats)=>{
        if(!err&&stats.isFile()){
            console.log(req.headers);
            resp.setHeader('Content-Type','video/mp4');
            resp.writeHead(200);
            fs.createReadStream(filepath).pipe(resp);
        }else{
            console.log(req.headers);
            resp.writeHead(404);
            resp.end('Not Found');
        }
    })
}).listen(8080);
console.log('Listen...');